<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/26
 * Time: 23:03
 */

class GetClassDetail_model extends MY_Model
{
    function get_class_detail($body)
    {
        $body = json_decode($body);
        $type = $body->type;
        $grade = $body->grade;
        $class = $body->class;

//        $sql = /** @lang text */
//            "SELECT b.`studentId`,c.`name`,b.`status` FROM ws_dict_grade AS a LEFT JOIN ws_class_$type AS b  ON a.`id`=b.`gradeId` LEFT JOIN ws_baseinfo AS c ON b.`studentId`=c.`id` LEFT JOIN ws_dict_class AS d ON b.`classId`=d.`id` WHERE a.`name`='一年级' AND d.`name`='1班'";

        $sql = /** @lang text */
            "SELECT c.`name`,a.`count`,b.`status` FROM ws_task_$type AS a LEFT JOIN ws_class_$type AS b ON a.`cid`=b.`id` LEFT JOIN ws_baseinfo AS c ON b.`studentId`=c.`id` LEFT JOIN ws_dict_grade AS g ON b.`gradeId`=g.`id` LEFT JOIN ws_dict_class AS h ON b.`classId`=h.`id` WHERE NOT EXISTS (SELECT 1 FROM ws_task_zuowen WHERE a.`cid`=cid AND a.`last_date`<last_date) AND g.`name`='$grade' AND h.`name`='$class'";

        $query = $this->db->query($sql);
        $data = array('count' => 0, 'data' => array(), 'result' => SUCCESS);
        foreach ($query->result_array() as $item => $value) {
            $sd = array();
            $sd['name'] = $value['name'];
            $sd['status'] = $value['status'];
            $sd['count'] = $value['count'];
            array_push($data['data'], $sd);
            $data['count'] += 1;
        }
        return json_encode($data);
    }
}